package cn.lkk.samples.lang.collections;

import java.util.*;

/**
 * 使用Iterator遍历数组
 */
public class IteratorTest {
    public static void main(String[] args) {
        List<Integer> nums = new ArrayList<Integer>(Arrays.asList(new Integer[]{2, 3, 1, 4, 5, 6, 2}));
        Iterator iterator = nums.iterator();
        System.out.println(nums);

        while (iterator.hasNext()) {
            Integer num = (Integer) iterator.next();
            if (num <= 2)
                iterator.remove();
        }

        System.out.println(nums);
    }
}
